﻿
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using Model.Components;
using FrameWork;
using FrameWork.Components;
using FrameWork.WebControls;

namespace Model.Web.Module.Model.Mao
{
    public partial class Manager : System.Web.UI.Page
    {
        Int32 IDX = (Int32)Common.sink("IDX", MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)Common.sink("CMD", MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            FrameWorkPermission.CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        private void BindYear()
        {
            int year = DateTime.Now.Year;
            tjYear_Input.Items.Add(new ListItem((year - 1).ToString(), (year - 1).ToString()));
            tjYear_Input.Items.Add(new ListItem(year.ToString(), year.ToString()));
            tjYear_Input.Items.Add(new ListItem((year + 1).ToString(), (year + 1).ToString()));
        }
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            MaoEntity ut = BusinessFacadeModel.MaoDisp(IDX);
            BindYear();
            OnStartData(ut);

            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看";
                    Hidden_Input();
                    Button1.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    ut.DataTable_Action_ = DataTable_Action.Delete;
                    if (BusinessFacadeModel.MaoInsertUpdateDelete(ut) > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Edit;
            bi.ButtonName = "矛盾纠纷统计";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = PopedomType.Delete;
            bi.ButtonName = "矛盾纠纷统计";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = PopedomType.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(MaoEntity ut)
        {
        tjYear_Input.Text = tjYear_Disp.Text = ut.tjYear.ToString();
                tjSea_Input.Text = tjSea_Disp.Text = ut.tjSea.ToString();
                a11_Input.Text = a11_Disp.Text = ut.a11.ToString();
                a12_Input.Text = a12_Disp.Text = ut.a12.ToString();
                a21_Input.Text = a21_Disp.Text = ut.a21.ToString();
                a22_Input.Text = a22_Disp.Text = ut.a22.ToString();
                a31_Input.Text = a31_Disp.Text = ut.a31.ToString();
                a32_Input.Text = a32_Disp.Text = ut.a32.ToString();
                a41_Input.Text = a41_Disp.Text = ut.a41.ToString();
                a42_Input.Text = a42_Disp.Text = ut.a42.ToString();
                a51_Input.Text = a51_Disp.Text = ut.a51.ToString();
                a52_Input.Text = a52_Disp.Text = ut.a52.ToString();
                a61_Input.Text = a61_Disp.Text = ut.a61.ToString();
                a62_Input.Text = a62_Disp.Text = ut.a62.ToString();
                a71_Input.Text = a71_Disp.Text = ut.a71.ToString();
                a72_Input.Text = a72_Disp.Text = ut.a72.ToString();
                a81_Input.Text = a81_Disp.Text = ut.a81.ToString();
                a82_Input.Text = a82_Disp.Text = ut.a82.ToString();
                a91_Input.Text = a91_Disp.Text = ut.a91.ToString();
                a92_Input.Text = a92_Disp.Text = ut.a92.ToString();
                a101_Input.Text = a101_Disp.Text = ut.a101.ToString();
                a102_Input.Text = a102_Disp.Text = ut.a102.ToString();
                a111_Input.Text = a111_Disp.Text = ut.a111.ToString();
                a112_Input.Text = a112_Disp.Text = ut.a112.ToString();
                a121_Input.Text = a121_Disp.Text = ut.a121.ToString();
                a122_Input.Text = a122_Disp.Text = ut.a122.ToString();
                a131_Input.Text = a131_Disp.Text = ut.a131.ToString();
                a132_Input.Text = a132_Disp.Text = ut.a132.ToString();
                a133_Input.Text = a133_Disp.Text = ut.a133.ToString();
                a141_Input.Text = a141_Disp.Text = ut.a141.ToString();
                a142_Input.Text = a142_Disp.Text = ut.a142.ToString();
                a15_Input.Text = a15_Disp.Text = ut.a15.ToString();
                a16_Input.Text = a16_Disp.Text = ut.a16.ToString();
                beizhu_Input.Text = beizhu_Disp.Text = ut.beizhu.ToString();
              
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
            tjYear_Input.Visible = false;
            tjSea_Input.Visible = false;
            a11_Input.Visible = false;
            a12_Input.Visible = false;
            a21_Input.Visible = false;
            a22_Input.Visible = false;
            a31_Input.Visible = false;
            a32_Input.Visible = false;
            a41_Input.Visible = false;
            a42_Input.Visible = false;
            a51_Input.Visible = false;
            a52_Input.Visible = false;
            a61_Input.Visible = false;
            a62_Input.Visible = false;
            a71_Input.Visible = false;
            a72_Input.Visible = false;
            a81_Input.Visible = false;
            a82_Input.Visible = false;
            a91_Input.Visible = false;
            a92_Input.Visible = false;
            a101_Input.Visible = false;
            a102_Input.Visible = false;
            a111_Input.Visible = false;
            a112_Input.Visible = false;
            a121_Input.Visible = false;
            a122_Input.Visible = false;
            a131_Input.Visible = false;
            a132_Input.Visible = false;
            a133_Input.Visible = false;
            a141_Input.Visible = false;
            a142_Input.Visible = false;
            a15_Input.Visible = false;
            a16_Input.Visible = false;
            beizhu_Input.Visible = false;
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
            tjYear_Disp.Visible = false;
            tjSea_Disp.Visible = false;
            a11_Disp.Visible = false;
            a12_Disp.Visible = false;
            a21_Disp.Visible = false;
            a22_Disp.Visible = false;
            a31_Disp.Visible = false;
            a32_Disp.Visible = false;
            a41_Disp.Visible = false;
            a42_Disp.Visible = false;
            a51_Disp.Visible = false;
            a52_Disp.Visible = false;
            a61_Disp.Visible = false;
            a62_Disp.Visible = false;
            a71_Disp.Visible = false;
            a72_Disp.Visible = false;
            a81_Disp.Visible = false;
            a82_Disp.Visible = false;
            a91_Disp.Visible = false;
            a92_Disp.Visible = false;
            a101_Disp.Visible = false;
            a102_Disp.Visible = false;
            a111_Disp.Visible = false;
            a112_Disp.Visible = false;
            a121_Disp.Visible = false;
            a122_Disp.Visible = false;
            a131_Disp.Visible = false;
            a132_Disp.Visible = false;
            a133_Disp.Visible = false;
            a141_Disp.Visible = false;
            a142_Disp.Visible = false;
            a15_Disp.Visible = false;
            a16_Disp.Visible = false;
            beizhu_Disp.Visible = false;
        }
        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            int tjYear_Value = (int)Common.sink(tjYear_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int tjSea_Value = (int)Common.sink(tjSea_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a11_Value = (int)Common.sink(a11_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a12_Value = (int)Common.sink(a12_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a21_Value = (int)Common.sink(a21_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a22_Value = (int)Common.sink(a22_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a31_Value = (int)Common.sink(a31_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a32_Value = (int)Common.sink(a32_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a41_Value = (int)Common.sink(a41_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a42_Value = (int)Common.sink(a42_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a51_Value = (int)Common.sink(a51_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a52_Value = (int)Common.sink(a52_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a61_Value = (int)Common.sink(a61_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a62_Value = (int)Common.sink(a62_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a71_Value = (int)Common.sink(a71_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a72_Value = (int)Common.sink(a72_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a81_Value = (int)Common.sink(a81_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a82_Value = (int)Common.sink(a82_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a91_Value = (int)Common.sink(a91_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a92_Value = (int)Common.sink(a92_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a101_Value = (int)Common.sink(a101_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a102_Value = (int)Common.sink(a102_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a111_Value = (int)Common.sink(a111_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a112_Value = (int)Common.sink(a112_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a121_Value = (int)Common.sink(a121_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a122_Value = (int)Common.sink(a122_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a131_Value = (int)Common.sink(a131_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a132_Value = (int)Common.sink(a132_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a133_Value = (int)Common.sink(a133_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a141_Value = (int)Common.sink(a141_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a142_Value = (int)Common.sink(a142_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a15_Value = (int)Common.sink(a15_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int a16_Value = (int)Common.sink(a16_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            string beizhu_Value = (string)Common.sink(beizhu_Input.UniqueID, MethodType.Post, 500, 0, DataType.Str);
            int tjDep_Value = UserData.GetUserDate.U_GroupID;
            DateTime? AddDate_Value = DateTime.Now;
                
            MaoEntity ut = BusinessFacadeModel.MaoDisp(IDX);
            
            ut.tjYear = tjYear_Value;
            ut.tjSea = tjSea_Value;
            ut.a11 = a11_Value;
            ut.a12 = a12_Value;
            ut.a21 = a21_Value;
            ut.a22 = a22_Value;
            ut.a31 = a31_Value;
            ut.a32 = a32_Value;
            ut.a41 = a41_Value;
            ut.a42 = a42_Value;
            ut.a51 = a51_Value;
            ut.a52 = a52_Value;
            ut.a61 = a61_Value;
            ut.a62 = a62_Value;
            ut.a71 = a71_Value;
            ut.a72 = a72_Value;
            ut.a81 = a81_Value;
            ut.a82 = a82_Value;
            ut.a91 = a91_Value;
            ut.a92 = a92_Value;
            ut.a101 = a101_Value;
            ut.a102 = a102_Value;
            ut.a111 = a111_Value;
            ut.a112 = a112_Value;
            ut.a121 = a121_Value;
            ut.a122 = a122_Value;
            ut.a131 = a131_Value;
            ut.a132 = a132_Value;
            ut.a133 = a133_Value;
            ut.a141 = a141_Value;
            ut.a142 = a142_Value;
            ut.a15 = a15_Value;
            ut.a16 = a16_Value;
            ut.beizhu = beizhu_Value;
            ut.tjDep = tjDep_Value;
            ut.AddDate = AddDate_Value;
            
            if (CMD == "New")
            {
                ut.DataTable_Action_ = DataTable_Action.Insert;
            }
            else if (CMD == "Edit")
            {
                ut.DataTable_Action_ = DataTable_Action.Update;
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            Int32 rInt = BusinessFacadeModel.MaoInsertUpdateDelete(ut);
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加矛盾纠纷统计成功!(ID:{0})", rInt);
                if (ut.DataTable_Action_ == DataTable_Action.Update)
                    OpTxt = string.Format("修改矛盾纠纷统计成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
